package tpase.KeyServer.Service.Impl;

import tpase.KeyServer.DAO.KeyShareDao;
import tpase.KeyServer.DAO.UserAuthDao;
import tpase.KeyServer.DO.KeyShare;
import tpase.KeyServer.DO.UserAuth;
import tpase.KeyServer.Service.KeyServerStartService;

public class KeyServerStartServiceImpl implements KeyServerStartService {
    private String serverId;
    private KeyShareDao keyShareDao;
    private UserAuthDao userAuthDao;

    public KeyServerStartServiceImpl(String serverId) {
        this.serverId = serverId;
        String configPath = "config/server" + serverId + "/config.properties";
        keyShareDao = new KeyShareDao(configPath);
        userAuthDao = new UserAuthDao(configPath);
    }

    @Override
    public KeyShare getKeyShare(String uid) {
        return keyShareDao.getKeyShare();
    }

    @Override
    public boolean hasUid(String uid) {
        UserAuth userAuth = userAuthDao.getUserAuth(uid);
        return userAuth != null;
    }

    @Override
    public void storeAuth(UserAuth userAuth) {
        userAuthDao.storeUserAuth(userAuth);
    }

    @Override
    public byte[] getUserAuth(String uid) {
        return userAuthDao.getUserAuth(uid).getAuth();
    }
}
